package com.lingkang.sales.config.database;

import com.alibaba.druid.pool.DruidDataSource;
import javax.sql.DataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author linke
 * @date 2020/11/18 22:56
 * @description
 */
@Configuration
public class DruidDataSourceConfig {

  @Primary //声明主数据源
  @Bean
  @ConfigurationProperties("spring.datasource.sales")
  public DataSource dataSource() {
    DruidDataSource source = new DruidDataSource();
    source.setDriverClassName("com.mysql.cj.jdbc.Driver");
    source.setName("sales");
    source.setInitialSize(1);
    //最大活动
    source.setMaxActive(10);
    source.setMaxWait(60000);
    //配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒
    source.setTimeBetweenEvictionRunsMillis(60000);
    //配置一个连接在池中最小生存的时间，单位是毫秒
    source.setMinEvictableIdleTimeMillis(300000);
    //每分钟打印一次连接状态日志
    //source.setTimeBetweenLogStatsMillis(60000);

    return source;
  }

  @Bean
  @ConfigurationProperties("spring.datasource.flowable")
  public DataSource flowableDataSource() {
    DruidDataSource source = new DruidDataSource();
    source.setDriverClassName("com.mysql.cj.jdbc.Driver");
    source.setName("flowable");
    source.setInitialSize(1);
    //最大活动
    source.setMaxActive(10);
    source.setMaxWait(60000);
    //配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒
    source.setTimeBetweenEvictionRunsMillis(60000);
    //配置一个连接在池中最小生存的时间，单位是毫秒
    source.setMinEvictableIdleTimeMillis(300000);
    //每分钟打印一次连接状态日志
    //source.setTimeBetweenLogStatsMillis(60000);
    return source;
  }

}
